home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form RotateForm
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- Caption = "Order of Rotation"
- ClientHeight = 5670
- ClientLeft = 825
- ClientTop = 915
- ClientWidth = 8190
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 1
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 6360
- KeyPreview = -1 'True
- Left = 765
- LinkTopic = "Form1"
- ScaleHeight = 5670
- ScaleWidth = 8190
- Top = 285
- Width = 8310
- Begin VB.PictureBox Proj
- AutoRedraw = -1 'True
- Height = 2655
- Index = 0
- Left = 0
- ScaleHeight = -5
- ScaleLeft = -2
- ScaleMode = 0 'User
- ScaleTop = 2
- ScaleWidth = 5
- TabIndex = 5
- Top = 3000
- Width = 2655
- End
- Begin VB.PictureBox Proj
- AutoRedraw = -1 'True
- Height = 2655
- Index = 1
- Left = 2760
- ScaleHeight = -5
- ScaleLeft = -2
- ScaleMode = 0 'User
- ScaleTop = 2
- ScaleWidth = 5
- TabIndex = 4
- Top = 3000
- Width = 2655
- End
- Begin VB.PictureBox Proj
- AutoRedraw = -1 'True
- Height = 2655
- Index = 2
- Left = 5520
- ScaleHeight = -5
- ScaleLeft = -2
- ScaleMode = 0 'User
- ScaleTop = 2
- ScaleWidth = 5
- TabIndex = 3
- Top = 3000
- Width = 2655
- End
- Begin VB.PictureBox Pict
- AutoRedraw = -1 'True
- Height = 2655
- Index = 2
- Left = 5520
- ScaleHeight = -5
- ScaleLeft = -2
- ScaleMode = 0 'User
- ScaleTop = 2
- ScaleWidth = 5
- TabIndex = 2
- Top = 240
- Width = 2655
- End
- Begin VB.PictureBox Pict
- AutoRedraw = -1 'True
- Height = 2655
- Index = 1
- Left = 2760
- ScaleHeight = -5
- ScaleLeft = -2
- ScaleMode = 0 'User
- ScaleTop = 2
- ScaleWidth = 5
- TabIndex = 1
- Top = 240
- Width = 2655
- End
- Begin VB.PictureBox Pict
- AutoRedraw = -1 'True
- Height = 2655
- Index = 0
- Left = 0
- ScaleHeight = -5
- ScaleLeft = -2
- ScaleMode = 0 'User
- ScaleTop = 2
- ScaleWidth = 5
- TabIndex = 0
- Top = 240
- Width = 2655
- End
- Begin VB.Label Label1
- Alignment = 2 'Center
- Caption = "Directly around a line"
- Height = 255
- Index = 2
- Left = 5520
- TabIndex = 8
- Top = 0
- Width = 2655
- End
- Begin VB.Label Label1
- Alignment = 2 'Center
- Caption = "Into X-Z plane first"
- Height = 255
- Index = 1
- Left = 2760
- TabIndex = 7
- Top = 0
- Width = 2655
- End
- Begin VB.Label Label1
- Alignment = 2 'Center
- Caption = "Into Y-Z plane first"
- Height = 255
- Index = 0
- Left = 0
- TabIndex = 6
- Top = 0
- Width = 2655
- End
- Begin VB.Menu mnuFile
- Caption = "&File"
- Begin VB.Menu mnuFileExit
- Caption = "E&xit"
- End
- End
- Attribute VB_Name = "RotateForm"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- ' Point being rotated into the Z axis.
- Const Px = 2
- Const Py = 2
- Const Pz = 1
- ' Line for direct rotation.
- Const Vx = 1
- Const Vy = 1
- Const Vz = 2
- ' Location of viewing eye.
- Dim EyeR As Single
- Dim EyeTheta As Single
- Dim EyePhi As Single
- ' Location of focus point.
- Const FocusX = 0#
- Const FocusY = 0#
- Const FocusZ = 0#
- Dim Projector(1 To 4, 1 To 4) As Single
- ' Matrices used for the reflection.
- Dim M1(1 To 4, 1 To 4) As Single
- Dim M2(1 To 4, 1 To 4) As Single
- Dim M3(1 To 4, 1 To 4) As Single
- Dim M4(1 To 4, 1 To 4) As Single
- Dim M5(1 To 4, 1 To 4) As Single
- Dim Identity(1 To 4, 1 To 4) As Single
- Sub CreateMatrices()
- Dim sin1 As Single
- Dim cos1 As Single
- Dim sin2 As Single
- Dim cos2 As Single
- Dim d1 As Single
- Dim d2 As Single
- m3Identity Identity
- ' *************
- ' * Y-Z first *
- ' *************
- d1 = Sqr(Px * Px + Pz * Pz)
- sin1 = -Px / d1
- cos1 = Pz / d1
- d2 = Sqr(Px * Px + Py * Py + Pz * Pz)
- sin2 = Py / d2
- cos2 = d1 / d2
- m3Identity M1 ' Around Y into Y-Z plane.
- M1(1, 1) = cos1
- M1(1, 3) = -sin1
- M1(3, 1) = sin1
- M1(3, 3) = cos1
- m3Identity M2 ' Around X into Z axis.
- M2(2, 2) = cos2
- M2(2, 3) = sin2
- M2(3, 2) = -sin2
- M2(3, 3) = cos2
-
- ' *************
- ' * X-Z first *
- ' *************
- d1 = Sqr(Py * Py + Pz * Pz)
- sin1 = Py / d1
- cos1 = Pz / d1
- d2 = Sqr(Px * Px + Py * Py + Pz * Pz)
- sin2 = -Px / d2
- cos2 = d1 / d2
- m3Identity M3 ' Around X into X-Z plane.
- M3(2, 2) = cos1
- M3(2, 3) = sin1
- M3(3, 2) = -sin1
- M3(3, 3) = cos1
- m3Identity M4 ' Around Y into Z axis.
- M4(1, 1) = cos2
- M4(1, 3) = -sin2
- M4(3, 1) = sin2
- M4(3, 3) = cos2
- ' ***************
- ' * Around line *
- ' ***************
- m3LineRotate M5, 0, 0, 0, Vx, Vy, Vz, PI
- End Sub
- ' ***********************************************
- ' Let the user change the location of the eye.
- ' ***********************************************
- Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
- Const Dtheta = PI / 20
- Select Case KeyCode
- Case vbKeyLeft
- EyeTheta = EyeTheta - Dtheta
-
- Case vbKeyRight
- EyeTheta = EyeTheta + Dtheta
-
- Case vbKeyUp
- EyePhi = EyePhi - Dtheta
-
- Case vbKeyDown
- EyePhi = EyePhi + Dtheta
-
- Case Else
- Exit Sub
- End Select
- ' Redraw the pictures.
- DrawTheData
- End Sub
- Private Sub Form_Load()
- ' Initialize the eye position.
- EyeR = 3
- EyeTheta = PI * 0.4
- EyePhi = PI * 0.1
- ' Create the rotation matrices.
- CreateMatrices
- ' Create, project, and draw the data.
- DrawTheData
- End Sub
- ' ***********************************************
- ' Draw all the pictures.
- ' ***********************************************
- Sub DrawTheData()
- Dim i As Integer
- ' Compute the projection matrix.
- m3PProject Projector, m3Parallel, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
- ' ***********************
- ' * Around Y axis first *
- ' ***********************
- CreateData
- TransformAllData Projector
- DrawSomeData Pict(0), 1, 3, vbRed, True
- DrawSomeData Pict(0), 5, NumSegments, ForeColor, False
- TransformData M1, 5, NumSegments
- SetPoints 5, NumSegments
- TransformData Projector, 5, NumSegments
- DrawSomeData Pict(0), 5, NumSegments, ForeColor, False
- TransformData M2, 5, NumSegments
- SetPoints 5, NumSegments
- TransformData Projector, 5, NumSegments
- DrawSomeData Pict(0), 5, NumSegments, ForeColor, False
- TransformAllData Identity
- DrawSomeData Proj(0), 1, 3, vbRed, True
- DrawSomeData Proj(0), 5, NumSegments, ForeColor, False
- ' ***********************
- ' * Around X axis first *
- ' ***********************
- CreateData
- TransformAllData Projector
- DrawSomeData Pict(1), 1, 3, vbRed, True
- DrawSomeData Pict(1), 5, NumSegments, ForeColor, False
-
- TransformData M3, 5, NumSegments
- SetPoints 5, NumSegments
- TransformData Projector, 5, NumSegments
- DrawSomeData Pict(1), 5, NumSegments, ForeColor, False
- TransformData M4, 5, NumSegments
- SetPoints 5, NumSegments
- TransformData Projector, 5, NumSegments
- DrawSomeData Pict(1), 5, NumSegments, ForeColor, False
- TransformAllData Identity
- DrawSomeData Proj(1), 1, 3, vbRed, True
- DrawSomeData Proj(1), 5, NumSegments, ForeColor, False
- ' ***************
- ' * Around line *
- ' ***************
- CreateData
- TransformAllData Projector
- DrawSomeData Pict(2), 1, 3, vbRed, True
- DrawSomeData Pict(2), 4, 4, vbBlue, False
- DrawSomeData Pict(2), 5, NumSegments, ForeColor, False
-
- TransformData M5, 5, NumSegments
- SetPoints 5, NumSegments
- TransformData Projector, 5, NumSegments
- DrawSomeData Pict(2), 5, NumSegments, ForeColor, False
- TransformAllData Identity
- DrawSomeData Proj(2), 1, 3, vbRed, True
- DrawSomeData Proj(2), 5, NumSegments, ForeColor, False
- For i = 0 To 2
- Pict(i).Refresh
- Proj(i).Refresh
- Next i
- End Sub
- Sub CreateData()
- ' Start with no data.
- NumSegments = 0
- ' Create the axes.
- MakeSegment 0, 0, 0, 5, 0, 0 ' X axis.
- MakeSegment 0, 0, 0, 0, 5, 0 ' Y axis.
- MakeSegment 0, 0, 0, 0, 0, 5 ' Z axis.
- ' Create the line.
- MakeSegment -2 * Vx, -2 * Vy, -2 * Vz, 2 * Vx, 2 * Vy, 2 * Vz
- ' Create the object to reflect.
- MakeSegment Px, Py, Pz, Px, Py - 1, Pz - 1
- MakeSegment Px, Py - 1, Pz - 1, Px, Py - 1, Pz + 1
- MakeSegment Px, Py - 1, Pz + 1, Px, Py, Pz
- End Sub
- Private Sub mnuFileExit_Click()
- Unload Me
- End Sub
-